package com.gemframework.common;

import java.io.Serializable;

public class Result<T> implements Serializable {

    public static final Result SYSTEM_ERROR_RESULT = Result.fail("System error");
    public static final Result SUCCESS_RESULT = Result.success(null);

    private Boolean success;
    private String errorMessage;
    private T data;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String message) {
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setErrorMessage(message);
        return result;
    }

}
